home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gekikoh Dennoh Club 1
/
Gekikoh Dennoh Club Vol. 1 (Japan).7z
/
Gekikoh Dennoh Club Vol. 1 (Japan) (Track 1).bin
/
tools
/
xb
/
xb2.has
< prev
next >
Wrap
Text File
|
1997-03-05
|
50KB
|
3,677 lines
*━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
*
* xb2.has …… ぺけ-BASICのインタプリタ本体
*
*━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
.include doscall.mac
.include iocscall.mac
.include fefunc.h
.include variable.h
.xref error
.xref errors
.xref dec_print
.xref init_tpal
.xref endendend
.xref I行数算出
.xref _breakflag
IERROR .macro num
bsr I行数算出
moveq #num,d0
bra error
.endm
IERRORS .macro num
bsr I行数算出
moveq #num,d0
bra errors
.endm
.offset 0
Aint: .ds.l 1
Astr: .ds.l 1
Afloat: .ds.l 1
Achar: .ds.l 1
orgSP: .ds.l 1
orgstrbuf: .ds.l 1
Adim:
.text
.even
.xdef basic_exec
basic_exec:
movea.l sp,a3 * AUTO 用
movea.l 4+変数INIT,a0
adda.w (a5)+,a0 * 変数確保リストの先頭アドレス
move.w 4+8(a0),d0 * 配列の個数 - 1
lsl.w #2,d0
add.w #Adim+4,d0 * Adim + 配列の個数 * 4
movea.l sp,a1
suba.w d0,sp * auto 変数のハンドルを収める領域を確保
movea.l sp,a4
move.l a1,orgSP(a4)
lea.l _SP上限(a6),a1
cmpa.l a1,sp
bcs stack_over
move.l a3,-(sp) * 保存&パラメーター渡し
tst.b d7
bmi auto_vc
lea.l Adim(a4),a1
move.l a1,配列
move.l a1,-(sp)
pea.l 変数float
pea.l 変数char
pea.l 変数str
pea.l 変数int
bra @f
auto_vc:
pea.l Adim(a4)
pea.l Afloat(a4)
pea.l Achar(a4)
pea.l Astr(a4)
pea.l Aint(a4)
@@:
bsr Variable_clr_sub * 変数領域確保 & 引き数セット
lea.l 4*5(sp),sp
movea.l (sp)+,a3
move.l strbuf,orgstrbuf(a4)
.xdef main_loop
main_loop:
move.l orgstrbuf(a4),strbuf
move.w _breakflag(pc),d0
beq @f
btst #breakoffF,d7
beq Stop
@@:
move.w (a5)+,d4
bmi 式
beq 関数呼び出し
statement:
move.w stt(pc,d4.w),d4
jmp stt(pc,d4.w)
stt:
.dc.w 関数呼び出し-stt *
.dc.w Color-stt
.dc.w Console-stt
.dc.w Locate-stt
.dc.w Lprint-stt
.dc.w Print-stt
.dc.w Width-stt
.dc.w Screen-stt
.dc.w Break-stt
.dc.w Case-stt *
.dc.w Continue-stt *10
.dc.w Default-stt *
.dc.w Endfunc-stt
.dc.w Switch2-stt
.dc.w Error-stt
.dc.w Return-stt
.dc.w Switch-stt
.dc.w Beep-stt
.dc.w Cls-stt
.dc.w End-stt
.dc.w Endwhile-stt *20
.dc.w Exit-stt
.dc.w For-stt
.dc.w Gosub-stt *
.dc.w Goto-stt
.dc.w If-stt
.dc.w Input-stt
.dc.w Key-stt
.dc.w Linput-stt
.dc.w Next-stt
.dc.w Next2-stt *30
.dc.w Stop-stt
.dc.w Until-stt
.dc.w While-stt
.dc.w Dim-stt
.dc.w ColorP-stt * 35
.dc.w FuncKey-stt * 36
.dc.w CursorSW-stt * 37
.dc.w Str-stt * 38
.dc.w Func-stt
.dc.w Else-stt *40
.dc.w SysVar-stt *41
.dc.w Ifeq-stt *42
.dc.w Ifne-stt
.dc.w Iflt-stt
.dc.w Ifgt-stt
.dc.w Ifle-stt
.dc.w Ifge-stt *47
関数呼び出し:
bsr function_call
bra main_loop
* 代入式だった
式:
btst #14,d4
beq 普通変数への代入
配列への代入:
* d4.b = 代入先の型
bsr 値get * 値を得る
move.l d0,d2
move.l d1,d3
movea.l a0,a1
bsr dim_set_sub * d2-d5/a1 保存
tst.b d4
beq int_setD
bmi float_setD
subq.b #1,d4
beq str_setD
*char_setD:
move.b d2,(a0,d0.l)
bra main_loop
str_setD:
lsl.l #8,d0
lea.l (a0,d0.l),a0
@@:
move.b (a1)+,(a0)+
bne @b
bra main_loop
float_setD:
.ifdef _XB030
movem.l d2-d3,(a0,d0.l*8)
.else
lsl.l #3,d0
movem.l d2-d3,(a0,d0.l)
.endif
bra main_loop
int_setD:
.ifdef _XB030
move.l d2,(a0,d0.l*4)
.else
lsl.l #2,d0
move.l d2,(a0,d0.l)
.endif
bra main_loop
普通変数への代入:
* d4.b = 代入先の型
bsr 値get * 値を得る
move.w (a5)+,d2 * 代入先の変数番号
bmi auto変数set
tst.b d4
beq int_set
bmi float_set
subq.b #1,d4
beq str_set
*char_set:
movea.l 変数char,a1 * とりあえず兼用
move.b d0,(a1,d2.w)
bra main_loop
float_set:
movea.l 変数float,a1 * とりあえず兼用
.ifdef _XB030
movem.l d0-d1,(a1,d2.w*8)
.else
lsl.w #3,d2
movem.l d0-d1,(a1,d2.w)
.endif
bra main_loop
str_set:
movea.l 変数str,a1 * とりあえず兼用
lsl.w #8,d2
lea.l (a1,d2.w),a1
@@:
move.b (a0)+,(a1)+
bne @b
bra main_loop
int_set:
movea.l 変数int,a1 * とりあえず兼用
.ifdef _XB030
move.l d0,(a1,d2.w*4)
.else
lsl.w #2,d2
move.l d0,(a1,d2.w)
.endif
bra main_loop
auto変数set:
not.w d2
tst.b d4
beq int_setA
bmi float_setA
subq.b #1,d4
beq str_setA
*char_set:
movea.l Achar(a4),a1
move.b d0,(a1,d2.w)
bra main_loop
float_setA:
movea.l Afloat(a4),a1
.ifdef _XB030
movem.l d0-d1,(a1,d2.w*8)
.else
lsl.w #3,d2
movem.l d0-d1,(a1,d2.w)
.endif
bra main_loop
str_setA:
movea.l Astr(a4),a1
lsl.w #8,d2
lea.l (a1,d2.w),a1
@@:
move.b (a0)+,(a1)+
bne @b
bra main_loop
int_setA:
movea.l Aint(a4),a1
.ifdef _XB030
move.l d0,(a1,d2.w*4)
.else
lsl.w #2,d2
move.l d0,(a1,d2.w)
.endif
bra main_loop
stack_over:
IERROR 8
** ** ** main_loop 部分終わり ** ** ** **
** ** ** ** ** ** ** ** **
float値get:
moveq #-1,d4
bra 値get
str値get:
moveq #1,d4
* (d4.b) 型の数式を評価して、( (d1/)d2-d4/a1 保存 )
* int の時、 d0 に値を返す
* float d0-d1
* str a0
値get: * どこかで d4.l を破壊している
move.w (a5)+,d0
tst.b d0
beq ig111
bmi fg111
cmpi.b #2,d0
beq cg111
*sg111:
cmpi.b #1,d4
bne 型違い
move.w d4,-(sp)
move.l d1,-(sp)
bsr str_get0
move.l (sp)+,d1
move.w (sp)+,d4
rts
cg111:
tst.w d0
bmi 1f
btst #14,d0
bne char_val
bsr int_cal * int でいい
bra @f **
1:
bclr #14,d0
beq char_imm
*char_fnc:
movem.l d1-d4/a1,-(sp)
bsr function_call
movem.l (sp)+,d1-d4/a1
tst.w (a0)
bne 返り値がない
move.l 2+4(a0),d0
bra 4f
char_val:
btst #13,d0
bne char_dim
btst #12,d0
bne str_point
btst #8,d0
beq 1f
movea.l Achar(a4),a0
bra 2f
1:
movea.l 変数char,a0 * とりあえず兼用
2:
move.w (a5)+,d0
move.b (a0,d0.w),d0
bra 4f
char_dim:
move.l d1,-(sp)
bsr dim_sub
move.l (sp)+,d1
move.b (a0,d0.l),d0
bra 4f
str_point:
btst #8,d0
bne 1f
bsr int値get
movea.l 変数str,a0 * とりあえず兼用
bra 2f
1:
bsr int値get
movea.l Astr(a4),a0
2:
cmpi.w #$100,d0
bcc str_access_err
move.l d1,-(sp)
move.w (a5)+,d1
lsl.w #8,d1
add.w d0,d1
move.b (a0,d1.w),d0
move.l (sp)+,d1
bra 4f
char_imm:
move.l (a5)+,d0
* bra 4f
4:
andi.l #$000000ff,d0 * char
bra @f
ig111:
tst.w d0
bmi 1f
bclr #14,d0
bne int_val
bsr int_cal
bra @f
int_val:
btst #13,d0
bne int_dim
btst #8,d0
bne auto_int_val
move.w (a5)+,d0
bge normal_int_var
bsr int_system_var
bra @f
1:
bclr #14,d0
beq int_imm
int_fnc:
movem.l d1-d4/a1,-(sp)
bsr function_call
movem.l (sp)+,d1-d4/a1
tst.w (a0)
bne 返り値がない
move.l 2+4(a0),d0
bra @f
normal_int_var:
movea.l 変数int,a0 * とりあえず兼用
.ifdef _XB030
move.l (a0,d0.w*4),d0
.else
lsl.w #2,d0
move.l (a0,d0.w),d0
.endif
bra @f
auto_int_val:
move.w (a5)+,d0
movea.l Aint(a4),a0
.ifdef _XB030
move.l (a0,d0.w*4),d0
.else
lsl.w #2,d0
move.l (a0,d0.w),d0
.endif
bra @f
int_dim:
move.l d1,-(sp)
bsr dim_sub
move.l (sp)+,d1
.ifdef _XB030
move.l (a0,d0.l*4),d0
.else
lsl.l #2,d0
move.l (a0,d0.l),d0
.endif
bra @f
int_imm:
move.l (a5)+,d0
* bra @f
@@:
tst.b d4
beq ig111_ok
bmi float_trans
cmpi.b #1,d4
beq 型違い * str
* andi.l #$000000ff,d0 * char
ig111_ok:
rts * int,char 同士
float_trans:
FPACK __LTOD * float <- int,char
rts
fg111:
move.l d1,-(sp) *
move.w d4,-(sp)
bsr float_get0
move.w (sp)+,d4
tst.b d4
beq int_trans
bmi fl_ok
cmpi.b #1,d4
beq 型違い
FPACK __DTOL * char <- float
andi.l #$ff,d0
move.l (sp)+,d1
rts
int_trans:
FPACK __DTOL * int <- float
move.l (sp)+,d1
rts
fl_ok:
addq.l #4,sp * float 同士
rts
int値get: * d4.l 保存!!
move.w (a5)+,d0
tst.b d0
beq ig112
bmi fg112
cmpi.b #2,d0
bne 型違い
*cg112:
tst.w d0
bmi 1f
btst #14,d0
bne char_val2
bsr int_cal * int でいい
rts
* bra 4f
1:
bclr #14,d0
beq char_imm2
*char_fnc2:
movem.l d1-d4/a1,-(sp)
bsr function_call
movem.l (sp)+,d1-d4/a1
tst.w (a0)
bne 返り値がない
move.l 2+4(a0),d0
bra 4f
char_val2:
btst #13,d0
bne char_dim2
btst #12,d0
bne str_point2
btst #8,d0
beq 1f
movea.l Achar(a4),a0
bra 2f
1:
movea.l 変数char,a0 * とりあえず兼用
2:
move.w (a5)+,d0
move.b (a0,d0.w),d0
bra 4f
char_dim2:
move.l d1,-(sp)
bsr dim_sub
move.l (sp)+,d1
move.b (a0,d0.l),d0
bra 4f
str_point2:
btst #8,d0
bne 1f
bsr int値get
movea.l 変数str,a0 * とりあえず兼用
bra 2f
1:
bsr int値get
movea.l Astr(a4),a0
2:
move.l d1,-(sp)
cmpi.w #$100,d0
bcc str_access_err
move.w (a5)+,d1
lsl.w #8,d1
add.w d0,d1
move.b (a0,d1.w),d0
move.l (sp)+,d1
bra 4f
char_imm2:
move.l (a5)+,d0
* bra 4f
4:
andi.l #$000000ff,d0 * char
rts
ig112:
tst.w d0
bmi 1f
bclr #14,d0
bne int_val2
bsr int_cal
rts
int_val2:
btst #13,d0
bne int_dim2
btst #8,d0
bne auto_int_val2
move.w (a5)+,d0
bge normal_int_var2
bra int_system_var
*bsr int_system_var
*rts
1:
bclr #14,d0
beq int_imm2
int_fnc2:
movem.l d1-d4/a1,-(sp)
bsr function_call
movem.l (sp)+,d1-d4/a1
tst.w (a0)
bne 返り値がない
move.l 2+4(a0),d0
rts
normal_int_var2:
movea.l 変数int,a0 * とりあえず兼用
.ifdef _XB030
move.l (a0,d0.w*4),d0
.else
lsl.w #2,d0
move.l (a0,d0.w),d0
.endif
rts
auto_int_val2:
move.w (a5)+,d0
movea.l Aint(a4),a0
.ifdef _XB030
move.l (a0,d0.w*4),d0
.else
lsl.w #2,d0
move.l (a0,d0.w),d0
.endif
rts
int_dim2:
move.l d1,-(sp)
bsr dim_sub
move.l (sp)+,d1
.ifdef _XB030
move.l (a0,d0.l*4),d0
.else
lsl.l #2,d0
move.l (a0,d0.l),d0
.endif
rts
int_imm2:
move.l (a5)+,d0
rts
fg112:
move.l d1,-(sp) *
move.w d4,-(sp)
bsr float_get0
move.w (sp)+,d4
FPACK __DTOL * int <- float
move.l (sp)+,d1
rts
型違い:
IERROR 31
返り値がない:
IERROR 49
* * * * * * * *
float_get0:
tst.w d0
bmi fg1
btst #14,d0
beq float_cal
* float_val
btst #13,d0
bne float_dim
btst #8,d0
beq 1f
movea.l Afloat(a4),a0
bra 2f
1:
movea.l 変数float,a0 * とりあえず兼用
2:
move.w (a5)+,d0
lsl.w #3,d0
movem.l (a0,d0.w),d0-d1
rts
float_dim:
bsr dim_sub
lsl.l #3,d0
movem.l (a0,d0.l),d0-d1
rts
fg1:
bclr #14,d0
beq float_imm
* float_fnc
movem.l d2-d4/a1,-(sp)
bsr function_call
movem.l (sp)+,d2-d4/a1
tst.w (a0)
bne 返り値がない
movem.l 2(a0),d0-d1
rts
float_imm:
movem.l (a5)+,d0/d1
rts
float_cal:
movem.l d2-d3,-(sp)
move.w (a5)+,d0
* add.w d0,d0
move.w fc(pc,d0.w),d0
jmp fc(pc,d0.w)
fc:
.dc.w 0 * dummy
.dc.w Fmul-fc
.dc.w Fdiv-fc
.dc.w Fdiv2-fc
.dc.w Fmod-fc
.dc.w Fadd-fc
.dc.w Fsub-fc
.dc.w Fshr-fc
.dc.w Fshl-fc
.dc.w Fequal-fc
.dc.w Fnoteq-fc
.dc.w Fsmall-fc
.dc.w Flarge-fc
.dc.w Feq_small-fc
.dc.w Feq_large-fc
.dc.w Fnot-fc
.dc.w Fand-fc
.dc.w FFor-fc
.dc.w Fxor-fc
.dc.w Fminus-fc
Fmul:
bsr float値get
move.l d0,d2
move.l d1,d3
bsr float値get
FPACK __DMUL * 手抜き
bra float_cal_end
Fdiv:
bsr float値get
move.l d0,d2
move.l d1,d3
bsr float値get
exg.l d0,d2
exg.l d1,d3
FPACK __DDIV * 手抜き
bra float_cal_end
Fdiv2:
bsr float値get
FPACK __DTOL
move.l d0,d2
bsr float値get
FPACK __DTOL
move.l d0,d1
move.l d2,d0
FPACK __LDIV * 手抜き
FPACK __LTOD
bra float_cal_end
Fmod:
bsr float値get
FPACK __DTOL
move.l d0,d2
bsr float値get
FPACK __DTOL
move.l d0,d1
move.l d2,d0
FPACK __LMOD * 手抜き
FPACK __LTOD
bra float_cal_end
Fadd:
bsr float値get
move.l d0,d2
move.l d1,d3
bsr float値get
FPACK __DADD * 手抜き
bra float_cal_end
Fsub:
bsr float値get
move.l d0,d2
move.l d1,d3
bsr float値get
exg.l d0,d2
exg.l d1,d3
FPACK __DSUB * 手抜き
bra float_cal_end
Fminus:
bsr float値get
bchg #31,d0 * 符号反転
bra float_cal_end
Fequal:
Fnoteq:
Fsmall:
Flarge:
Feq_small:
Feq_large:
Fshr:
Fshl:
Fnot:
Fand:
FFor:
Fxor:
.xdef floatにない演算
floatにない演算:
IERROR 2
float_cal_end:
movem.l (sp)+,d2-d3
rts
** ** ** ** ** **
str_get0:
tst.w d0
bmi sg1
btst #14,d0
beq str_cal
* str_val
btst #13,d0
bne str_dim
btst #8,d0
bne auto_str_var
move.w (a5)+,d0
bge normal_str_var
* str_system_var
add.w d0,d0
move.w str_sys(pc,d0.w),d0
jmp str_sys(pc,d0.w)
.dc.w Inkey0-str_sys
.dc.w Inkey-str_sys
.dc.w Time-str_sys
.dc.w Day-str_sys
.dc.w Date-str_sys
str_sys:
Date:
IOCS _DATEGET
move.l d0,d1 * BCD
IOCS _DATEBIN
move.l d0,d1 * binary
lsl.l #4,d1
ori.b #$02,d1 * yy/mm/dd
ror.l #4,d1
movea.l strbuf,a0
addi.l #$100,strbuf
move.l a1,-(sp)
movea.l a0,a1
IOCS _DATEASC
move.l (sp)+,a1
rts
Day:
IOCS _DATEGET
swap d0
lsr.w #8,d0
moveq #0,d1
move.b d0,d1 * 曜日
movea.l strbuf,a0
addi.l #$100,strbuf
move.l a1,-(sp)
movea.l a0,a1
IOCS _DAYASC
move.l (sp)+,a1
rts
Time:
IOCS _TIMEGET
move.l d0,d1 * BCD
IOCS _TIMEBIN
move.l d0,d1 * binary
movea.l strbuf,a0
addi.l #$100,strbuf
move.l a1,-(sp)
movea.l a0,a1
IOCS _TIMEASC
move.l (sp)+,a1
rts
Inkey0:
move.w #1,-(sp)
DOS _KEYCTRL
addq.l #2,sp
tst.l d0
beq @f
clr.w -(sp)
DOS _KEYCTRL
addq.l #2,sp
@@:
movea.l strbuf,a0
addi.l #$100,strbuf
clr.w (a0)
move.b d0,(a0)
rts
Inkey:
bsr cursor_on
@@:
clr.w -(sp)
DOS _KEYCTRL
addq.l #2,sp
tst.b d0 * 一部のFEPにバグがあるらしい( 島崎さん )
beq @b
movea.l strbuf,a0
addi.l #$100,strbuf
clr.w (a0)
move.b d0,(a0)
bra cursor_off
* bsr cursor_off
* rts
normal_str_var:
movea.l 変数str,a0 * とりあえず兼用
lsl.w #8,d0
lea.l (a0,d0.w),a0
rts
auto_str_var:
move.w (a5)+,d0
movea.l Astr(a4),a0
lsl.w #8,d0
lea.l (a0,d0.w),a0
rts
str_dim:
bsr dim_sub
lsl.l #8,d0
lea.l (a0,d0.l),a0
rts
sg1:
bclr #14,d0
beq str_imm
* str_fnc
movem.l d2-d4/a1,-(sp)
bsr function_call
tst.w (a0)
bne 返り値がない
movea.l 2+4(a0),a1
movea.l strbuf,a0
addi.l #$100,strbuf
move.l a0,d2 * 保存
@@:
move.b (a1)+,(a0)+
bne @b
movea.l d2,a0
movem.l (sp)+,d2-d4/a1
rts
str_imm:
movea.l a5,a0
@@:
tst.b (a5)+
bne @b
addq.l #1,a5
move.l a5,d0
bclr #0,d0
movea.l d0,a5
rts
str_cal:
move.w (a5)+,d0
cmpi.w #5*2,d0 * '+'
bne strに足し算以外
movea.l strbuf,a0
addi.l #$100,strbuf
movem.l a0/a1,-(sp)
move.w #255-1,d1
movea.l a0,a1
bsr str値get
@@:
move.b (a0)+,(a1)+
dbeq d1,@b
subq.l #1,a1
bsr str値get
@@:
move.b (a0)+,(a1)+
dbeq d1,@b
clr.b (a1)
movem.l (sp)+,a0/a1
rts
** ** ** ** ** **
** ** ** ** ** **
int_system_var:
add.w d0,d0
move.w int_sys(pc,d0.w),d0
jmp int_sys(pc,d0.w)
.dc.w Pos-int_sys
.dc.w Free-int_sys
.dc.w Errno-int_sys
.dc.w Csrlin-int_sys
int_sys:
Csrlin:
move.l d1,-(sp)
moveq #-1,d1
IOCS _B_LOCATE * dos_call で出来ないかなぁ
move.l (sp)+,d1
swap d0
clr.w d0
swap d0
add.w scroll開始行,d0
rts
Pos:
move.l d1,-(sp)
moveq #-1,d1
IOCS _B_LOCATE * dos_call で出来ないかなぁ
move.l (sp)+,d1
* swap d0
clr.w d0
swap d0
rts
Free:
move.l mem_last,d0
sub.l 変数area,d0
rts
Errno:
move.l errorno,d0
rts
int_cal:
move.w (a5)+,d0
move.w ic(pc,d0.w),d0
jmp ic(pc,d0.w)
ic:
.dc.w 0 * dummy
.dc.w Imul-ic
.dc.w Idiv-ic
.dc.w Idiv2-ic
.dc.w Imod-ic
.dc.w Iadd-ic
.dc.w Isub-ic
.dc.w Ishr-ic
.dc.w Ishl-ic
.dc.w Iequal-ic
.dc.w Inoteq-ic
.dc.w Ismall-ic
.dc.w Ilarge-ic
.dc.w Ieq_small-ic
.dc.w Ieq_large-ic
.dc.w Inot-ic
.dc.w Iand-ic
.dc.w Ior-ic
.dc.w Ixor-ic
.dc.w Iminus-ic * $13
.dc.w 0 * reserve $14
.dc.w 0 * reserve $15
.dc.w 0 * reserve $16
.dc.w 0 * reserve $17
.dc.w 0 * reserve $18
.dc.w 0 * reserve $19
.dc.w 0 * reserve $1a
.dc.w 0 * reserve $1b
.dc.w 0 * reserve $1c
.dc.w 0 * reserve $1d
.dc.w 0 * reserve $1e
.dc.w 0 * reserve $1f
.dc.w Iadd1-ic * $20
.dc.w Iadd2-ic
.dc.w Iadd3-ic
.dc.w Iadd4-ic
.dc.w Iadd5-ic
.dc.w Iadd6-ic
.dc.w Iadd7-ic
.dc.w Iadd8-ic
.dc.w Isub1-ic * $28
.dc.w Isub2-ic
.dc.w Isub3-ic
.dc.w Isub4-ic
.dc.w Isub5-ic
.dc.w Isub6-ic
.dc.w Isub7-ic
.dc.w Isub8-ic
.dc.w Imul02-ic * $30
.dc.w Imul03-ic
.dc.w Imul04-ic
.dc.w Imul05-ic
.dc.w Imul06-ic
.dc.w Imul07-ic
.dc.w Imul08-ic
.dc.w Imul09-ic
.dc.w Imul10-ic
.dc.w Imul11-ic
.dc.w Imul12-ic
.dc.w Imul13-ic
.dc.w Imul14-ic
.dc.w Imul15-ic
.dc.w Imul16-ic
.dc.w 0 * reserve $3f
.dc.w Imul32-ic
.dc.w Imul64-ic
.dc.w Imul128-ic
.dc.w Imul256-ic
.dc.w 0 * reserve $44
.dc.w 0 * reserve $45
.dc.w 0 * reserve $46
.dc.w 0 * reserve $47
.dc.w Idiv2_1-ic * $48
.dc.w Idiv2_2-ic
.dc.w Idiv2_3-ic
.dc.w Idiv2_4-ic
.dc.w Idiv2_5-ic
.dc.w Idiv2_6-ic
.dc.w Idiv2_7-ic
.dc.w Idiv2_8-ic
.dc.w Ishr1-ic * $50
.dc.w Ishr2-ic
.dc.w Ishr3-ic
.dc.w Ishr4-ic
.dc.w Ishr5-ic
.dc.w Ishr6-ic
.dc.w Ishr7-ic
.dc.w Ishr8-ic
Imul:
.ifdef _XB030
bsr int値get
move.l d0,-(sp)
bsr int値get
muls.l (sp)+,d0
.else
move.l d1,-(sp)
bsr int値get
move.l d0,d1
bsr int値get
FPACK __LMUL
move.l (sp)+,d1
.endif
rts
Idiv:
Idiv2:
.ifdef _XB030
move.l d1,-(sp)
bsr int値get
move.l d0,d1
bsr int値get
tst.l d0
beq zero_div
exg d0,d1
divs.l d1,d0
move.l (sp)+,d1
.else
move.l d1,-(sp)
bsr int値get
move.l d0,d1
bsr int値get
tst.l d0
beq zero_div
exg d0,d1
FPACK __LDIV * 手抜き
move.l (sp)+,d1
.endif
rts
Imod:
.ifdef _XB030
move.l d1,-(sp)
bsr int値get
move.l d0,d1
bsr int値get
tst.l d0
beq zero_div
divsl.l d0,d0:d1
move.l (sp)+,d1
.else
move.l d1,-(sp)
bsr int値get
move.l d0,d1
bsr int値get
tst.l d0
beq zero_div
exg d0,d1
FPACK __LMOD * 手抜き
move.l (sp)+,d1
.endif
rts
Iadd:
bsr int値get
move.l d0,-(sp)
bsr int値get
add.l (sp)+,d0
rts
Isub:
move.l d1,-(sp)
bsr int値get
move.l d0,d1
bsr int値get
sub.l d0,d1
move.l d1,d0
move.l (sp)+,d1
rts
Ishr:
move.l d1,-(sp)
bsr int値get
move.l d0,d1
bsr int値get
lsr.l d0,d1
move.l d1,d0
move.l (sp)+,d1
rts
Ishl:
move.l d1,-(sp)
bsr int値get
move.l d0,d1
bsr int値get
lsl.l d0,d1
move.l d1,d0
move.l (sp)+,d1
rts
* 実数・文字列の比較の時有り
二数比較:
* tst.b d0
bmi 二比float
subq.b #2,d0
beq 二比char
*二比str:
movem.l d4/a1,-(sp)
bsr str値get
move.l a0,a1
bsr str値get
@@:
move.b (a0)+,d0
beq @f
cmp.b (a1)+,d0
beq @b
movem.l (sp)+,d4/a1
rts
@@:
cmp.b (a1),d0
movem.l (sp)+,d4/a1
rts
二比float:
move.w d4,-(sp)
bsr float値get
move.l d0,d2
move.l d1,d3
bsr float値get
move.w (sp)+,d4
FPACK __DCMP
rts
二比char:
bsr int値get
move.l d0,d1
bsr int値get
cmp.b d1,d0
rts
Iequal:
move.l d1,-(sp)
move.b 1(a5),d0
beq 二比int_eq
bsr 二数比較
beq true
bra false
二比int_eq:
bsr int値get
move.l d0,d1
bsr int値get
cmp.l d1,d0
beq true
bra false
Inoteq:
move.l d1,-(sp)
move.b 1(a5),d0
beq 二比int_ne
bsr 二数比較
bne true
bra false
二比int_ne:
bsr int値get
move.l d0,d1
bsr int値get
cmp.l d1,d0
bne true
bra false
Ismall:
move.l d1,-(sp)
move.b 1(a5),d0
beq @f
bsr 二数比較
bhi true
bra false
@@:
bsr int値get
move.l d0,d1
bsr int値get
cmp.l d1,d0
bgt true
bra false
Ilarge:
move.l d1,-(sp)
move.b 1(a5),d0
beq @f
bsr 二数比較
bcs true
bra false
@@:
bsr int値get
move.l d0,d1
bsr int値get
cmp.l d1,d0
blt true
bra false
Ieq_small:
move.l d1,-(sp)
move.b 1(a5),d0
beq @f
bsr 二数比較
bcc true
bra false
@@:
bsr int値get
move.l d0,d1
bsr int値get
cmp.l d1,d0
bge true
bra false
Ieq_large:
move.l d1,-(sp)
move.b 1(a5),d0
beq @f
bsr 二数比較
bls true
bra false
@@:
bsr int値get
move.l d0,d1
bsr int値get
cmp.l d1,d0
ble true
bra false
true:
moveq #-1,d0
move.l (sp)+,d1
rts
false:
moveq #0,d0
move.l (sp)+,d1
rts
Inot:
bsr int値get
not.l d0
rts
Iand:
bsr int値get
move.l d0,-(sp)
bsr int値get
and.l (sp)+,d0
rts
Ior:
bsr int値get
move.l d0,-(sp)
bsr int値get
or.l (sp)+,d0
rts
Ixor:
move.l d1,-(sp)
bsr int値get
move.l d0,d1
bsr int値get
eor.l d1,d0
move.l (sp)+,d1
rts
Iminus:
bsr int値get
neg.l d0
rts
.irpc ch,12345678
Iadd&ch:
bsr int値get
addq.l #&ch,d0
rts
.endm
.irpc ch,12345678
Isub&ch:
bsr int値get
subq.l #&ch,d0
rts
.endm
Idiv2_1:
bsr int値get
tst.l d0
bge @f
addq.l #1,d0
@@:
asr.l #1,d0
rts
Idiv2_2:
bsr int値get
tst.l d0
bge @f
addq.l #3,d0
@@:
asr.l #2,d0
rts
Idiv2_3:
bsr int値get
tst.l d0
bge @f
addq.l #7,d0
@@:
asr.l #3,d0
rts
.irpc ch,45678
Idiv2_&ch:
bsr int値get
tst.l d0
bge @f
neg.l d0
asr.l #&ch,d0
neg.l d0
rts
@@:
asr.l #&ch,d0
rts
.endm
.irpc ch,12345678
Ishr&ch:
bsr int値get
lsr.l #&ch,d0
rts
.endm
Imul02:
bsr int値get
add.l d0,d0
rts
Imul03:
bsr int値get
move.l d0,-(sp)
add.l d0,d0
add.l (sp)+,d0
rts
Imul04:
bsr int値get
lsl.l #2,d0
rts
Imul05:
bsr int値get
move.l d0,-(sp)
lsl.l #2,d0
add.l (sp)+,d0
rts
Imul06:
bsr int値get
add.l d0,d0
move.l d0,-(sp)
add.l d0,d0
add.l (sp)+,d0
rts
Imul07:
bsr int値get
move.l d0,-(sp)
lsl.l #3,d0
sub.l (sp)+,d0
rts
Imul08:
bsr int値get
lsl.l #3,d0
rts
Imul09:
bsr int値get
move.l d0,-(sp)
lsl.l #3,d0
add.l (sp)+,d0
rts
Imul10:
bsr int値get
add.l d0,d0
move.l d0,-(sp)
lsl.l #2,d0
add.l (sp)+,d0
rts
Imul11:
bsr int値get
move.l d0,-(sp)
add.l d0,d0
add.l d0,(sp)
lsl.l #2,d0
add.l (sp)+,d0
rts
Imul12:
bsr int値get
lsl.l #2,d0
move.l d0,-(sp)
add.l d0,d0
add.l (sp)+,d0
rts
Imul13:
bsr int値get
move.l d0,-(sp)
lsl.l #2,d0
add.l d0,(sp)
add.l d0,d0
add.l (sp)+,d0
rts
Imul14:
bsr int値get
add.l d0,d0
move.l d0,-(sp)
lsl.l #3,d0
sub.l (sp)+,d0
rts
Imul15:
bsr int値get
move.l d0,-(sp)
lsl.l #4,d0
sub.l (sp)+,d0
rts
Imul16:
bsr int値get
lsl.l #4,d0
rts
Imul32:
bsr int値get
lsl.l #5,d0
rts
Imul64:
bsr int値get
lsl.l #6,d0
rts
Imul128:
bsr int値get
lsl.l #7,d0
rts
Imul256:
bsr int値get
lsl.l #8,d0
rts
.xdef strに足し算以外
strに足し算以外:
IERROR 2
zero_div:
IERROR 69
.xdef dim_sub
dim_sub:
move.w (a5)+,d1 * 配列番号
btst #8,d0
beq @f
lea.l Adim(a4),a0
bra dim3
.xdef dim_set_sub
dim_set_sub:
move.w (a5)+,d1 * 配列番号
bge @f
not.w d1
lea.l Adim(a4),a0 * auto
bra dim3
@@:
movea.l 配列,a0 * global
dim3:
.ifdef _XB030
movea.l (a0,d1.w*4),a0 * 配列ポインタ
.else
lsl.w #2,d1
movea.l (a0,d1.w),a0 * 配列ポインタ
.endif
move.w 4(a0),d1 * 次元 - 1
addq.l #8,a0
beq one_dim
* 二次元以上の時
movem.l d2-d5/a1,-(sp)
move.w d1,d5
.ifdef _XB030
lea.l 2(a0,d1.w*2),a1
.else
add.w d1,d1
lea.l 2(a0,d1.w),a1
.endif
moveq #0,d1
bra dim4
dim5:
.ifdef _XB030
mulu.l (a1)+,d0
add.l d0,d1
.else
move.l d1,d2
move.l (a1)+,d1
FPACK __UMUL
move.l d0,d1
add.l d2,d1
.endif
dim4:
move.l a0,-(sp)
bsr int値get
movea.l (sp)+,a0
cmpi.l #$10000,d0
bcc 添え字大きすぎ
cmp.w (a0)+,d0 * 添え字の大きさ
bhi 添え字大きすぎ
dbra d5,dim5
add.l d1,d0
movea.l a1,a0
movem.l (sp)+,d2-d5/a1
rts
one_dim: * 一次元の時
move.l a0,-(sp)
bsr int値get
move.l (sp)+,a0
cmpi.l #$10000,d0
bcc 添え字大きすぎ1
cmp.w (a0)+,d0 * 添え字の大きさ
bhi 添え字大きすぎ2
rts
添え字大きすぎ1:
.if 0
move.l d0,-(sp)
bsr dec_print
move.l #$10000,(sp)
bsr dec_print
bra @f
.endif
添え字大きすぎ2:
.if 0
move.l d0,-(sp)
bsr dec_print
moveq #0,d1
move.w -2(a0),d1
move.l d1,(sp)
bsr dec_print
@@:
addq.l #4,sp
.endif
添え字大きすぎ:
tst.l d0
bmi @f
IERROR 37
@@:
IERROR 38
** ** ** ** ** ** ** **
* 各ステートメントごとの処理
Gosub: * サポートの予定は未定
IERROR 10
Case: * 呼ばれるはずのないステートメント
Default:
.xdef noSTAT
noSTAT:
IERROR 2
Func:
IERROR 76
SysVar:
bsr str値get
tst.w (a5)+
beq SetDate
SetTime:
movea.l a0,a1
IOCS _TIMECNV
move.l d0,d1
bmi ireg_set_sysvar
IOCS _TIMEBCD
move.l d0,d1
IOCS _TIMESET
bra main_loop
SetDate:
movea.l a0,a1
IOCS _DATECNV
move.l d0,d1
bmi ireg_set_sysvar
IOCS _DATEBCD
move.l d0,d1
IOCS _DATESET
bra main_loop
ireg_set_sysvar:
IERROR 70
Error:
tst.w (a5)+
beq ErrorOff
bclr #errorF,d7
bra main_loop
ErrorOff:
bset #errorF,d7
bra main_loop
Key:
bsr int値get
tst.w d0
beq key_err
cmpi.w #20,d0
bhi key_err
ori.w #$100,d0
subq.l #4,sp
move.w d0,-(sp)
bsr str値get
move.l a0,2(sp)
DOS _FNCKEY
addq.l #6,sp
bra main_loop
key_err:
IERROR 64
* 文字列ポインタへの代入
Str:
bsr int値get * 代入ポインタ
move.l d0,d1
cmpi.w #$100,d1
bcc str_access_err
bsr int値get * ほんとは char だけど
move.w (a5)+,d2 * str変数番号
bge 1f
not.w d2
movea.l Astr(a4),a0
bra 2f
1:
movea.l 変数str,a0 * とりあえず兼用
2:
lsl.w #8,d2
add.w d1,d2
tst.b (a0,d2.w)
* beq @f
move.b d0,(a0,d2.w)
bra main_loop
*@@:
* move.b d0,(a0,d2.w)
* clr.b 1(a0,d2.w) * 文字列の最後だった時のための用心
* bra main_loop
str_access_err:
IERROR 41
* 配列の初期化
Dim:
move.w (a5)+,d1 * 型
bmi 可変長配列定義
movea.l 配列,a1
move.w (a5)+,d0 * 配列番号
bpl @f
lea.l Adim(a4),a1
not.w d0
@@:
lsl.w #2,d0
movea.l (a1,d0.w),a1
move.w 4(a1),d0 * 次元
add.w d0,d0
move.w d0,d2
add.w d0,d0
add.w d2,d0 * 6倍
lea.l 10(a1,d0.w),a1 * データ領域先頭
move.w (a5)+,d2 * 個数 - 1
tst.b d1
beq int_dim_init
bmi float_dim_init
subq.b #1,d1
bne char_dim_init
str_dim_init:
movea.l a1,a0
@@:
move.b (a5)+,(a0)+
bne @b
lea.l $100(a1),a1
dbra d2,str_dim_init
bra @f
char_dim_init:
move.b (a5)+,(a1)+
dbra d2,char_dim_init
@@:
addq.l #1,a5
move.l a5,d0
bclr #0,d0
movea.l d0,a5
bra main_loop
float_dim_init:
move.l (a5)+,(a1)+
move.l (a5)+,(a1)+
dbra d2,float_dim_init
bra main_loop
int_dim_init:
move.l (a5)+,(a1)+
dbra d2,int_dim_init
bra main_loop
可変長配列定義:
move.w (a5)+,d0 * 配列番号
move.w (a5)+,d3 * 次元 - 1
movea.l 変数area,a1
btst #0,d3
bne @f * 奇数次元の時に
addq.l #2,a1 * 配列の要素がロングワード境界に来るように小細工
@@:
not.w d0
lsl.w #2,d0
move.l a1,Adim(a4,d0.w)
clr.l (a1)+ * offset (無効)
move.w d3,(a1)+ * 次元-1
bsr dim_clr_sub1
move.w d3,d1 * 次元 - 1
@@:
bsr int値get
move.w d0,(a1)+ * 添え字の大きさ
swap d0
tst.w d0
bne 添字大きさ不正
dbra d1,@b
bsr dim_clr_sub2
lea.l (a1,d0.l),a0
cmpa.l mem_last,a0
bcc mem_err
btst #v_initF,d7
beq @f
andi.b #$fc,d0
adda.l d0,a1
bra 1f
@@:
lsr.l #2,d0
moveq #0,d1
bsr a1_clr_d0Lx4
1:
move.l a1,変数area
bra main_loop
添字大きさ不正:
IERROR 36
Switch:
bsr int値get * 値1
adda.l (a5),a5 *** JUMP *** switch table
move.w (a5)+,d2 * case の個数 - 1
bra @f
sw_loop:
addq.l #4,a5
@@:
cmp.l (a5)+,d0
dbeq d2,sw_loop
beq sw_default
addq.l #4,a5
sw_default:
adda.l (a5),a5 *** JUMP ***
bra main_loop
.xdef Switch2
Switch2:
bsr str値get * 値1
moveq #-2,d0 * 文字列長さ
movea.l a0,a1
@@:
addq.w #1,d0
tst.b (a1)+
bne @b
adda.l (a5),a5 *** JUMP *** switch table
move.w (a5)+,d2 * case の個数 - 1
sw_loop2:
move.w (a5)+,d1 * 文字列長さ
cmp.w d0,d1
bne sw2_out
tst.w d1
bmi sw2_ok
movea.l a0,a1
movea.l a5,a2
@@:
cmp.b (a1)+,(a2)+
dbne d0,@b
bne sw2_out2
sw2_ok:
addq.w #3,d1
bclr #0,d1
adda.w d1,a5
bra sw_default
sw2_out2:
move.w d1,d0 * H9/3/5 switch (文字列) の不都合の原因?
sw2_out:
addq.w #3+4,d1 * jump address skip
bclr #0,d1
adda.w d1,a5
dbra d2,sw_loop2
bra sw_default
For:
bsr int値get * 値1
move.l d0,d1
move.w (a5)+,d0 * 変数番号
bmi for_0
movea.l 変数int,a0 * とりあえず兼用
bra @f
for_0:
not.w d0
movea.l Aint(a4),a0
@@:
lsl.w #2,d0
move.l d1,(a0,d0.w)
bsr int値get * 値2
cmp.l d1,d0
blt Break ; changed from bcs (M.Kamada 95.07.09)
addq.l #4,a5
bra main_loop
Goto:
Else:
Break:
Continue:
adda.l (a5),a5 *** JUMP ***
bra main_loop
If:
While:
Until:
bsr int値get * 値1
tst.l d0
bne 条件真
* 偽
adda.l (a5),a5 *** JUMP ***
bra main_loop
条件真:
addq.l #4,a5
bra main_loop
Ifeq:
bsr int値get * 値1
move.l d0,d1
bsr int値get * 値2
cmp.l d0,d1
beq 条件真
adda.l (a5),a5 *** JUMP ***
bra main_loop
Ifne:
bsr int値get * 値1
move.l d0,d1
bsr int値get * 値2
cmp.l d0,d1
bne 条件真
adda.l (a5),a5 *** JUMP ***
bra main_loop
Ifgt:
bsr int値get * 値1
move.l d0,d1
bsr int値get * 値2
cmp.l d0,d1
bgt 条件真
adda.l (a5),a5 *** JUMP ***
bra main_loop
Ifge:
bsr int値get * 値1
move.l d0,d1
bsr int値get * 値2
cmp.l d0,d1
bge 条件真
adda.l (a5),a5 *** JUMP ***
bra main_loop
Iflt:
bsr int値get * 値1
move.l d0,d1
bsr int値get * 値2
cmp.l d0,d1
blt 条件真
adda.l (a5),a5 *** JUMP ***
bra main_loop
Ifle:
bsr int値get * 値1
move.l d0,d1
bsr int値get * 値2
cmp.l d0,d1
ble 条件真
adda.l (a5),a5 *** JUMP ***
bra main_loop
Endwhile:
bsr int値get * 値1
tst.l d0
beq 条件偽
* 真
adda.l (a5),a5 *** JUMP ***
bra main_loop
条件偽:
addq.l #4,a5
bra main_loop
Next2:
move.w (a5)+,d0 * 変数番号
bmi 1f
movea.l 変数int,a0 * とりあえず兼用
bra @f
1:
not.w d0
movea.l Aint(a4),a0
@@:
lsl.w #2,d0
addq.l #1,(a0,d0.w)
move.l (a0,d0.w),d1
cmp.l (a5)+,d1 * 特別
bgt for_loop終わった
adda.l (a5),a5 *** JUMP ***
bra main_loop
Next:
move.w (a5)+,d0 * 変数番号
bmi next0
movea.l 変数int,a0 * とりあえず兼用
bra @f
next0:
not.w d0
movea.l Aint(a4),a0
@@:
lsl.w #2,d0
addq.l #1,(a0,d0.w)
move.l (a0,d0.w),d1
bsr int値get * 値2
cmp.l d0,d1
bgt for_loop終わった
adda.l (a5),a5 *** JUMP ***
bra main_loop
for_loop終わった:
addq.l #4,a5
bra main_loop
Console:
bsr int値get
subq.l #2,sp
move.w d0,-(sp)
move.w d0,scroll開始行
bsr int値get
move.w d0,2(sp)
add.w (sp),d0
cmpi.w #32,d0
bhi console_para_err
bne @f
move.l #$000e_ffff,-(sp)
DOS _CONCTRL
addq.l #4,sp
subq.w #3,d0
bne console_para_err
@@:
move.w #15,-(sp)
DOS _CONCTRL
addq.l #6,sp
bra screen_end
console_para_err:
IERROR 53
FuncKey:
bsr int値get
move.l d0,d1
subq.w #1,d0
bhi func_mode_error
move.l #$000e_ffff,-(sp)
DOS _CONCTRL
tst.w d1
beq FuncOff
*FuncOn
tst.l d0
beq 1f
* move.l #$000e_0000,(sp) * console 0,31,1
clr.w 2(sp)
bra @f
FuncOff:
subq.l #3,d0
beq 1f
move.l #$000e_0002,(sp) * console 0,31,0
DOS _CONCTRL
move.l #$000e_0003,(sp) * 最下行有効
@@:
DOS _CONCTRL
1:
addq.l #4,sp
bra screen_end
func_mode_error:
IERROR 73
Width:
bsr int値get
cmpi.w #64,d0
beq width64
moveq #0,d1
cmpi.w #96,d0
beq width96
IERROR 24
width64:
moveq #2,d1
tas sinitFLAG * 512x512 にした時だけフラグセット
width96:
move.w d1,-(sp)
move.w #16,-(sp) * 画面サイズ指定モード
DOS _CONCTRL
move.l #$000e_0000,(sp) * console 0,31,1
DOS _CONCTRL
addq.l #4,sp
bsr init_tpal * テキストパレット初期化
bra main_loop
Screen:
bsr int値get * 値1:表示画面サイズ
cmpi.w #2,d0
bhi screen_mode_error
beq sc768
moveq #1,d1
eor d0,d1
bsr int値get * 値2:実画面及び色モード
cmpi.w #3,d0
bhi screen_mode_error
add.w d0,d0
or.w d0,d1
add.w d1,d1 * 抜けてる?
bsr int値get * 値3:ディスプレイ解像度
subq.w #1,d0
beq @f
bhi screen_mode_error
addq.w #1,d1
@@:
bsr int値get * 値4:GRAPHIC表示ON/OFF
subq.w #1,d0
beq screen_g_init * モード変更前にチェック、モード変更後に初期化
bhi screen_mode_error
IOCS _CRTMOD * dos_call で出来ないかなぁ
screen_end:
tas sinitFLAG *bset #7
bra main_loop
screen_g_init:
bsr check_g_use_mode
bne screen_g_use_error
IOCS _CRTMOD
IOCS _G_CLR_ON
bra screen_end
sc768:
bsr int値get * 値2
tst.w d0
bne screen_mode_error
bsr int値get * 値3
subq.w #1,d0
tst.w d0
bne screen_mode_error
bsr int値get * 値4
move.w d0,-(sp)
subq.w #1,d0
bmi @f
bhi screen_mode_error
bsr check_g_use_mode
bne screen_g_use_error
@@
move.w #16,-(sp)
DOS _CONCTRL
addq.l #4,sp
bra screen_end
screen_mode_error:
IERROR 71 * モードが異常
screen_g_use_error:
IERROR 72 * グラフィック画面は使用中
* GRAPHIC の使用状況を調べる by Eriko * を中谷が てきとー にいじった。
check_g_use_mode:
move.w d1,-(sp)
clr.w d1
moveq #-1,d2
IOCS _TGUSEMD
move.w (sp)+,d1
tst.b d0 * 未使用
beq @f
subq.b #3,d0 * 破壊
@@: rts
ColorP:
moveq #0,d1 * text color
moveq #4-1,d3
@@:
tst.w (a5)+
bne 1f
move.w d3,-(sp)
bsr int値get
move.l d0,d2
IOCS _TPALET
move.w (sp)+,d3
1:
addq.w #1,d1
bset #6,sinitFLAG * 1回でも変更したらセット
dbra d3,@b
bra main_loop
Color:
bsr int値get
move.w d0,d1
IOCS _B_COLOR
bra main_loop
Locate:
bsr int値get
subq.l #4,sp
move.w d0,(sp) * X 座標
bsr int値get
sub.w scroll開始行,d0
bcs @f
move.w d0,2(sp) * Y 座標
move.w #3,-(sp)
DOS _CONCTRL
addq.l #6,sp
bra main_loop
@@:
IERROR 44
CursorSW:
bsr int値get
tst.l d0
bne CursorON
bclr #cursorF,d7
beq main_loop
move.w #18,-(sp) * cursor off
bra @f
CursorON:
bset #cursorF,d7
bne main_loop
move.w #17,-(sp) * cursor on
@@:
DOS _CONCTRL
addq.l #2,sp
bra main_loop
Beep::
move.w #7,-(sp) * beep 音
DOS _PUTCHAR
addq.l #2,sp
bra main_loop
Cls:
move.l #$000a_0002,-(sp) * 画面全体消去
DOS _CONCTRL
addq.l #4,sp
bra main_loop
inp_sub:
tst.b (a5)+
bne inp_sub
addq.l #1,a5
move.l a5,d0
bclr #0,d0
movea.l d0,a5
rts
Input:
move.l a5,-(sp)
Inp_retry:
DOS _PRINT
pea.l hatena(pc)
DOS _PRINT
addq.l #4,sp
move.l (sp),a5
bsr inp_sub
bsr cursor_on
lea.l tmp,a1
move.l a1,-(sp)
move.w #$ff00,(a1)+
DOS _GETS
pea.l _crlf(pc)
DOS _PRINT
addq.l #8,sp
bsr cursor_off
move.w _breakflag(pc),d0
bne Stop
Inp_loop:
lea.l $100+tmp,a0
moveq #0,d1 * 実体あり?
iii1:
move.b (a1),d0
beq iii2
moveq #1,d1
addq.l #1,a1
cmpi.b #',',d0
beq iii2
move.b d0,(a0)+
bra iii1
iii2:
cmpi.b #$20,-1(a0)
bne iii3
subq.l #1,a0
bra iii2
iii3:
clr.b (a0)
lea.l $100+tmp,a0
move.w (a5)+,d2
beq Inp_int
bmi Inp_float
cmpi.w #$0100,d2
beq Inp_str
cmpi.w #$0200,d2
beq Inp_char
tst.b d1
bne Inp_データ多い
addq.l #4,sp
bra main_loop
Inp_str:
move.w (a5)+,d2
bmi 1f
movea.l 変数str,a2 * とりあえず兼用
bra 2f
1:
not.w d2
movea.l Astr(a4),a2
2:
lsl.w #8,d2
lea.l (a2,d2.w),a2
tst.b (a0)
beq Inp_loop
@@:
move.b (a0)+,(a2)+
bne @b
bra Inp_loop
Inp_int:
move.w (a5)+,d2
bmi 1f
movea.l 変数int,a2 * とりあえず兼用
bra 2f
1:
not.w d2
movea.l Aint(a4),a2
2:
lsl.w #2,d2
tst.b (a0)
beq Inp_loop
bsr inpget
move.l d0,(a2,d2.w)
tst.b (a0)
beq Inp_loop
bra inp型違い
Inp_char:
move.w (a5)+,d2
bmi 1f
movea.l 変数char,a2 * とりあえず兼用
bra 2f
1:
not.w d2
movea.l Achar(a4),a2
2:
tst.b (a0)
beq Inp_loop
bsr inpget
move.b d0,(a2,d2.w)
tst.b (a0)
beq Inp_loop
bra inp型違い
Inp_float:
move.w (a5)+,d2
bmi 1f
movea.l 変数float,a2 * とりあえず兼用
bra 2f
1:
not.w d2
movea.l Afloat(a4),a2
2:
lsl.w #3,d2
tst.b (a0)
beq Inp_loop
movem.l d2-d3,-(sp)
FPACK __VAL
movem.l (sp)+,d2-d3
movem.l d0-d1,(a2,d2.w)
tst.b (a0)
beq Inp_loop
bra inp型違い
Inp_データ多い:
pea.l _Inp_データ多い(pc)
bra @f
inp型違い:
pea.l _inp型違い(pc)
@@:
DOS _PRINT
addq.l #4,sp
bra Inp_retry
_Inp_データ多い:
.dc.b 7,'データの個数が多いんちゃいますか',13,10,0
_inp型違い:
.dc.b 7,'データの型が違いますねん',13,10,0
hatena:
.dc.b '? ',0
.even
inpget:
cmpi.b #'&',(a0)
beq 定数etc
FPACK __STOL
rts
定数etc:
addq.l #1,a0
moveq #$20,d0
or.b (a0)+,d0
cmpi.b #'h',d0
beq 定数HEX
cmpi.b #'b',d0
beq 定数BIN
cmpi.b #'o',d0
beq 定数OCT
addq.l #4,sp * 邪道
bra inp型違い
定数BIN:
FPACK __STOB
rts
定数OCT:
FPACK __STOO
rts
定数HEX:
FPACK __STOH
rts
Linput:
move.l a5,-(sp)
DOS _PRINT
addq.l #4,sp
bsr inp_sub
bsr cursor_on
lea.l tmp,a0
move.l a0,-(sp)
move.w #$ff00,(a0)+
DOS _GETS
pea.l _crlf(pc)
DOS _PRINT
addq.l #8,sp
bsr cursor_off
move.w _breakflag(pc),d0
bne Stop
move.w (a5)+,d2
bmi linput_Astr
movea.l 変数str,a1 * とりあえず兼用
bra @f
linput_Astr:
not.w d2
movea.l Astr(a4),a1
@@:
lsl.w #8,d2
lea.l (a1,d2.w),a1
@@:
move.b (a0)+,(a1)+
bne @b
bra main_loop
print: .macro
.local l1
.local l2
tst.w d7
bge l1
DOS _FPUTS
bra l2
l1:
DOS _PRINT
l2:
.endm
Lprint:
move.w #4,-(sp) * prn
bset #localF,d7
bra @f
Print:
bclr #localF,d7
@@:
move.w (a5)+,d4
bge print_ctrl
bsr 値get
tst.b d4
beq int_print
bmi float_print
subq.b #1,d4
beq str_print
*char_print:
int_print:
lea.l tmp,a0
move.l a0,-(sp)
move.b #$20,(a0)+
FPACK __LTOS
move.b #$20,(a0)+
clr.b (a0)
print
addq.l #4,sp
bra Print
* move.l d0,-(sp)
* bsr dec_print
* addq.l #4,sp
* bra Print
float_print:
lea.l tmp,a0
move.l a0,-(sp)
move.b #$20,(a0)+
FPACK __DTOS
move.b #$20,(a0)+
clr.b (a0)
print
addq.l #4,sp
bra Print
str_print:
movea.l a0,a1
moveq #-1,d2
moveq #$20,d1
moveq #0,d0
ccloop:
addq.w #1,d2
move.b (a1)+,d0
beq ctrlcodeなし
cmp.b d1,d0
bcc ccloop
add.w d0,d0
move.w _cc(pc,d0.w),d0
beq ccloop
lea.l tmp,a1
move.l a1,-(sp)
subq.w #1,d2
bcs kokop3
@@:
move.b (a0)+,(a1)+
dbra d2,@b
kokop3:
lea.l _cc(pc,d0.w),a2
@@:
move.b (a2)+,(a1)+
bne @b
clr.b (a1)
print
addq.l #4,sp
addq.l #1,a0
bra str_print
_cc:
.dc.w 0 * 00
.dc.w 0
.dc.w 0
.dc.w 0
.dc.w 0
.dc.w 0
.dc.w 0
.dc.w 0
.dc.w 0 * 08
.dc.w cc_tab-_cc
.dc.w cc_lf-_cc
.dc.w cc_home-_cc * 0b
.dc.w cc_clr-_cc * 0c
.dc.w cc_cr-_cc
.dc.w 0
.dc.w 0 *cc_Rdown-_cc
.dc.w 0 *cc_Rup-_cc
.dc.w 0
.dc.w 0
.dc.w 0
.dc.w 0
.dc.w 0
.dc.w 0
.dc.w 0
.dc.w 0 * 18
.dc.w 0
.dc.w cc_Cj-_cc * 1a
.dc.w cc_ESC-_cc
.dc.w cc_r-_cc * 1c
.dc.w cc_l-_cc * 1d
.dc.w cc_u-_cc * 1e
.dc.w cc_d-_cc * 1f
cc_tab: .dc.b 9,0
cc_lf: .dc.b $a,0
cc_home: .dc.b $1e,0
cc_clr: .dc.b $1a,0
cc_cr: .dc.b $d,0
cc_Cj: .dc.b $1b,'[J',0
cc_ESC .dc.b $1b,0
cc_r: .dc.b $1b,'[C',0
cc_l: .dc.b $1b,'[D',0
cc_u: .dc.b $b,0
cc_d: .dc.b $1b,'[B',0
*cc_crlf: .dc.b $d,$a,0
*cc_Rup: .dc.b $1b,'[s',$1b,'[32;H',$a,$1b,'[u',$1b,'[L',0
*cc_Rdown: .dc.b $1b,'[L',0
.even
ctrlcodeなし:
move.l a0,-(sp)
print
addq.l #4,sp
bra Print
print_ctrl:
move.w _pc(pc,d4.w),d4
jmp _pc(pc,d4.w)
_pc:
.dc.w crlf_end-_pc
.dc.w print_end-_pc
.dc.w tab-_pc
.dc.w using_num-_pc
.dc.w using_str-_pc
using_str:
bsr str値get
lea.l tmp,a1
move.l a1,-(sp)
move.w (a5)+,d0
@@:
move.b (a0)+,(a1)+
dbeq d0,@b
bne us_str_調整いらず
subq.l #1,a1
@@:
move.b #$20,(a1)+ * 後ろ余った時の調整
dbra d0,@b
us_str_調整いらず:
clr.b (a1)
bra using_common
using_num:
bsr float値get
lea.l tmp,a0
move.l a0,-(sp)
* move.w (a5)+,d2
* move.w (a5)+,d3
* move.w (a5)+,d4
* ext.l d2
* ext.l d3
* ext.l d4
movem.w (a5)+,d2/d3/d4 *符号拡張するのでこれでOK by Eriko
FPACK __USING
using_common:
print
addq.l #4,sp
bra Print
tab:
move.w #$9,-(sp) * ','
DOS _PUTCHAR
addq.l #2,sp
bra Print
crlf_end:
pea.l _crlf(pc)
print
addq.l #4,sp
print_end:
tst.w d7
bge main_loop
addq.l #2,sp * prn
bra main_loop
ここまでprint:
subq.w #1,d2
bcs kokop1
lea.l tmp,a1
move.l a1,-(sp)
@@:
move.b (a0)+,(a1)+
dbra d2,@b
clr.b (a1)
print
addq.l #4,sp
kokop1:
addq.l #1,a0
rts
_crlf:
.dc.b 13,10,0
.even
Return:
move.l orgstrbuf(a4),strbuf
move.w (a5)+,d4
move.w d4,-(sp)
bsr 値get
lea.l ret_dat(pc),a1
move.w (sp)+,d4
beq intRET
tst.b d4
bmi floatRET
subq.w #2,d4
beq intRET * ほんとは char だけど
*strRET:
move.l a0,6(a1)
bra _ret
floatRET:
movem.l d0-d1,2(a1)
bra _ret
intRET:
move.l d0,6(a1)
bra _ret
Endfunc:
move.l orgstrbuf(a4),strbuf
lea.l no_ret_dat(pc),a1
_ret:
movea.l a1,a0
movea.l orgSP(a4),sp
moveq #0,d0
rts
.align 4
no_ret_dat:
.dc.w -1
ret_dat:
.dc.w 0
.dc.l 0,0
Stop:
clr.b ed_filename * エディタ起動せず
IERROR 54
Exit:
bsr int値get
move.w d0,EXITcode
End:
bra endendend
** ** ** ** ** ** ** ** **
cursor_on:
btst #cursorF,d7
beq @f
move.w #17,-(sp) * cursor on
DOS _CONCTRL
addq.l #2,sp
@@:
rts
cursor_off:
btst #cursorF,d7
beq @f
move.w #18,-(sp) * cursor off
DOS _CONCTRL
addq.l #2,sp
@@:
rts
** ** ** ** ** ** ** ** **
* d4.b = 型
.xdef function_call
function_call:
move.w (a5)+,d2 * 引き数の個数
move.w d2,d0
lsl.w #4,d0 * いっぱい余るけどいいよね
neg.w d0
lea.l -4*(3+5)-2(sp,d0.w),sp
*レジスタ退避+引き数の個数+引き数(10*個数)
movea.l sp,a1
move.w d2,(a1)+ * 引き数の個数
subq.w #1,d2
bcs fnc_call_loop_end
fnc_call_loop:
move.w (a5)+,d4
bmi 引き数は式
btst #$e,d4
bne 引き数は配列
cmpi.b #$ff,d4
beq 引き数は省略
IERROR 18
引き数は省略:
move.w #$ffff,(a1)+
addq.l #8,a1
bra fnc_call_cont
引き数は配列:
btst #$d,d4
bne 引き数はポインタ
btst #8,d4
bne 引き数はauto配列
movea.l 配列,a0
bra @f
引き数はauto配列:
lea.l Adim(a4),a0
@@:
move.w (a5)+,d0
lsl.w #2,d0
clr.w (a1)+ * これでいい? 調べないと
addq.l #4,a1
move.l (a0,d0.w),(a1)+
bra fnc_call_cont
引き数はポインタ:
moveq #0,d0
move.w (a5)+,d0
tst.b d4
beq intPT
bmi floatPT
cmpi.b #1,d4
bne charPT
strPT:
lsl.l #8,d0
btst #8,d4
bne strPTA
movea.l 変数str,a0
bra @f
strPTA:
movea.l Astr(a4),a0
bra @f
charPT:
btst #8,d4
bne charPTA
movea.l 変数char,a0
bra @f
charPTA:
movea.l Achar(a4),a0
bra @f
floatPT:
lsl.l #3,d0
btst #8,d4
bne floatPTA
movea.l 変数float,a0
bra @f
floatPTA:
movea.l Afloat(a4),a0
bra @f
intPT:
lsl.l #2,d0
btst #8,d4
bne intPTA
movea.l 変数int,a0
bra @f
intPTA
movea.l Aint(a4),a0
@@:
adda.l d0,a0
clr.w (a1)+ * これでいい? 調べないと
addq.l #4,a1
move.l a0,(a1)+
bra fnc_call_cont
引き数は式:
tst.b d4
beq intP
bmi floatP
subq.b #1,d4
bne charP * char
strP:
moveq #1,d4
move.w d2,-(sp)
bsr 値get
move.w (sp)+,d2
move.w #3,(a1)+ * str
addq.l #4,a1
* clr.l (a1)+
move.l a0,(a1)+
bra fnc_call_cont
charP: * char
move.w #2,(a1)+ * char
bra @f
floatP:
move.w d2,-(sp)
bsr 値get
move.w (sp)+,d2
clr.w (a1)+ * float
move.l d0,(a1)+
move.l d1,(a1)+
bra fnc_call_cont
intP:
move.w #1,(a1)+ * int
@@:
move.w d2,-(sp)
bsr int値get
move.w (sp)+,d2
addq.l #4,a1
* clr.l (a1)+
move.l d0,(a1)+
fnc_call_cont:
dbra d2,fnc_call_loop
fnc_call_loop_end:
move.w (a5)+,d0 * 関数番号
bmi 内部関数呼出
lsl.w #4,d0
movea.l 関数buf,a0
movea.l $c(a0,d0.w),a0 * 関数実行アドレス
move.w (sp),d2 * 引き数の個数
lsl.w #4,d2 * いっぱい余るけどいいよね
movem.l d5-d7/a2-a6,2(sp,d2.w)
jsr (a0) * 関数呼び出し
move.w (sp),d2 * 引き数の個数
lsl.w #4,d2 * いっぱい余るけどいいよね
lea.l 2(sp,d2.w),sp
movem.l (sp)+,d5-d7/a2-a6
move.l d0,errorno
beq 無事実行
lea.l dummy_fac(pc),a0 * 返り値を用意していない関数用?
btst #errorF,d7
bne 無事実行 * error off
.xref 最左カラム
bsr 最左カラム
move.l a1,-(sp)
DOS _PRINT
IERROR 20
無事実行:
rts
dummy_fac:
.dc.w 0
.dc.l 0,-1 * error の時の返り値
内部関数呼出:
not.w d0
lsl.w #4,d0
movea.l 内部関数buf,a0
movea.l 変数area,a2 * 保存
move.w (sp),d2 * 引き数の個数
lsl.w #4,d2 * いっぱい余るけどいいよね
movem.l d5-d7/a2-a6,2(sp,d2.w)
movea.l $c(a0,d0.w),a5 * 関数実行アドレス
move.l a5,d0
beq 内部関数のアドレスなし
bset #modeF,d7 * 内部関数フラグセット
bsr basic_exec * 関数呼び出し
move.w (sp),d2 * 引き数の個数
lsl.w #4,d2 * いっぱい余るけどいいよね
lea.l 2(sp,d2.w),sp
movem.l (sp)+,d5-d7/a2-a6
move.l a2,変数area * 復活
rts
.xdef 内部関数のアドレスなし
内部関数のアドレスなし:
IERROR 2
** ** ** ** ** ** ** **
.offset 4
Fint: .ds.l 1
Fstr: .ds.l 1
Fchar: .ds.l 1
Ffloat: .ds.l 1
Fdim: .ds.l 1
F引数: .ds.l 1
.text
Variable_clr_sub:
* move.w (a5)+,d0
* movea.l 4+変数INIT,a0
* adda.w d0,a0
movea.l 変数area,a1
move.l (a0)+,d0
lea.l (a1,d0.l),a2
cmpa.l mem_last,a2
bcc mem_err
btst #v_initF,d7
beq 1f
movea.l Fint(sp),a2
move.l a1,(a2)
move.w (a0)+,d0 * int
addq.w #1,d0
lsl.w #2,d0
adda.w d0,a1
movea.l Fstr(sp),a2
move.l a1,(a2)
move.w (a0)+,d0 * str
addq.w #1,d0
lsl.w #8,d0 * 128 個までしかできないけど大丈夫?
adda.w d0,a1
movea.l Fchar(sp),a2
move.l a1,(a2)
move.w (a0)+,d0 * char
addq.w #1+3,d0
andi.w #$fffc,d0
adda.w d0,a1
movea.l Ffloat(sp),a2
move.l a1,(a2)
move.w (a0)+,d0 * float
addq.w #1,d0
lsl.w #2,d0
adda.w d0,a1
bra @f
1:
moveq #0,d1
movea.l Fint(sp),a2
move.l a1,(a2)
move.w (a0)+,d0 * int
addq.w #1,d0
bsr a1_clr_d0x4
movea.l Fstr(sp),a2
move.l a1,(a2)
move.w (a0)+,d0 * str
addq.w #1,d0
lsl.w #8-2,d0
bsr a1_clr_d0x4
movea.l Fchar(sp),a2
move.l a1,(a2)
move.w (a0)+,d0 * char
addq.w #1+3,d0
lsr.w #2,d0
bsr a1_clr_d0x4
movea.l Ffloat(sp),a2
move.l a1,(a2)
move.w (a0)+,d0 * float
addq.w #1,d0
add.w d0,d0
bsr a1_clr_d0x4
@@:
配列初期:
movea.l Fdim(sp),a2
move.w (a0)+,d4 * 配列の個数 - 1
bmi 配列初期end
配列初期loop:
moveq #0,d3
move.b (a0)+,d3 * 次元 - 1
move.b (a0)+,d1 * 型
btst #0,d3
bne @f * 奇数次元の時に
addq.l #2,a1 * 配列の要素がロングワード境界に来るように小細工
@@:
move.l a1,(a2)+ * 配列ポインタ
clr.l (a1)+ * offset (無効)
move.w d3,(a1)+ * 次元
bsr dim_clr_sub1
move.w d3,d1 * 次元 - 1
@@:
move.w (a0)+,(a1)+ * 添え字の大きさ
dbra d1,@b
bsr dim_clr_sub2
btst #v_initF,d7
beq 1f
andi.b #$fc,d0
adda.l d0,a1
bra 配列初期cont
1:
lsr.l #2,d0
moveq #0,d1
bsr a1_clr_d0Lx4
配列初期cont:
dbra d4,配列初期loop
配列初期end:
move.l a1,変数area
** ** ** **
* 引き数のセット
movea.l 4+引数INIT,a0
adda.w (a5)+,a0 * 引き数リストの先頭アドレス
move.w (a0)+,d3 * 引き数個数 - 1
bmi 引き数setend
movea.l F引数(sp),a1
addq.l #4+2,a1 * stack に積んである引き数の先頭
引き数setloop:
move.w (a0)+,d0 * 型
bmi @f
move.w (a0)+,d2 * 配列番号
movea.l Fdim(sp),a2
lsl.w #2,d2
move.l 6(a1),(a2,d2.w) * 配列ポインタ
bra 引き数setcont
@@:
move.w (a0)+,d2 * 番号
tst.b d0
beq int引数
bmi float引数
subq.b #1,d0
beq str引数
* char
movea.l Fchar(sp),a2
movea.l (a2),a2
move.b 6+3(a1),(a2,d2.w)
bra 引き数setcont
str引数:
movea.l Fstr(sp),a2
lsl.w #8,d2
movea.l (a2),a2
lea.l (a2,d2.w),a2
move.l a0,-(sp)
movea.l 6(a1),a0
@@:
move.b (a0)+,(a2)+
bne @b
move.l (sp)+,a0
bra 引き数setcont
float引数:
movea.l Ffloat(sp),a2
lsl.w #3,d2
movea.l (a2),a2
move.l 2(a1),(a2,d2.w)
move.l 6(a1),4(a2,d2.w)
bra 引き数setcont
int引数:
movea.l Fint(sp),a2
lsl.w #2,d2
movea.l (a2),a2
move.l 6(a1),(a2,d2.w)
引き数setcont:
lea.l 10(a1),a1
dbra d3,引き数setloop
引き数setend:
rts
dim_clr_sub1:
moveq #4,d0 * 各項のデータサイズを見る
moveq #2,d2 * size (shift)
tst.b d1 * 型
beq 1f
bmi 2f * float
subq.b #1,d1
beq 3f * str
moveq #1,d0 * char
moveq #0,d2
bra 1f
3:
move.w #$100,d0 * str
moveq #8,d2
bra 1f
2:
moveq #8,d0 * float
moveq #3,d2
1:
move.w d0,(a1)+ * 各項のデータサイズ(1 or 4 or 8 or 256)
rts
dim_clr_sub2:
move.w d3,d1 * 次元 - 1
lsl.w #2,d1
lea.l (a1,d1.w),a3
move.l a3,-(sp)
moveq #1,d0
bra 1f
@@:
move.l d0,-(a3) * 配列計算用のオフセット
1:
moveq #0,d1
move.w -(a1),d1
addq.l #1,d1
FPACK __UMUL
dbra d3,@b
movea.l (sp)+,a1
lsl.l d2,d0
addq.l #3,d0 * 忘れてた
rts
a1_clr_d0Lx4:
subq.l #1,d0
bmi a1_clr_d0x4_end
@@:
move.l d1,(a1)+
dbra d0,@b
clr.w d0
subq.l #1,d0
bcc @b
rts
a1_clr_d0x4:
subq.w #1,d0
bmi a1_clr_d0x4_end
@@:
move.l d1,(a1)+
dbra d0,@b
a1_clr_d0x4_end:
rts
mem_err:
IERROR 1
.end